package org.msn.gui.controller;

import javafx.fxml.FXML;
import javafx.scene.control.TextField;
import javafx.scene.input.MouseEvent;
import org.msn.client.handler.RequestHandler;
import org.msn.gui.init.MsnInit;
import org.msn.gui.init.ParentInit;
import org.msn.rest.RestCode;
import org.msn.rest.RestResult;
import org.msn.dto.RoomInfoDTO;
import org.msn.enumerate.CodeEnum;
import org.msn.gui.constant.APIConstant;
import org.msn.util.RequestUtil;

public class CreateRoomController extends ParentInit {
    @FXML
    private TextField roomName;

    @FXML
    private TextField number;

    public void cancel(MouseEvent mouseEvent) {
        ShowAllRoomController.exportAddRoomStage.close();
    }

    public void confirm(MouseEvent mouseEvent) {
        ShowAllRoomController.exportAddRoomStage.close();

        sendCreateRoom(ctx, RoomInfoDTO
                .builder()
                .name(roomName.getText())
                .number(Integer.valueOf(number.getText()))
                .username((String) APIConstant.CONFIG.get("name"))
                .build());

        // 寄存房间名
        MsnInit.exportRoomName.setText(roomName.getText());
        // 显示房间名在面板上
        MsnInit.exportRoomName.setText(roomName.getText());

        MsnController.exportShowAllRoomStage.close();
    }
}
